//点击显示产品详情
dianji();
function dianji(){
$('#result>div').click(function () {
    var id =$(this).attr("lei");
    $('#details').empty();
    $('body').css('overflow', 'hidden');
    new Ajax("/product_list.jsp").keyvalue("id",id).getJson(function(json){
        $.each(json,function(key,val){
            $('#details').append('<span>关闭</span><h3>产品详情</h3><img src="/upfile/' + val["pt"] + '"/><h4>' + val["name"] + '</h4><p>价格：' + val["ptprice"] + '</p><p>库存量：' + val["inventory"] + '</p><p>产地：' + val["ptplace"] + '</p><h5></h5><h3>详情介绍</h3><table><tr><td>品牌：</td><td>' +val["brandnames"] + '</td></tr><tr><td>型号：</td><td>' + val["ptmodel"] + '</td></tr><tr><td>制造商：</td><td>' + val["manufacturers"] + '</td></tr><tr><td>规格参数：</td><td>' + val["parameters"] + '</td></tr></table>');
        });
    $('#background').show();
    //关闭详情窗口
    $('#details>span').on('click', function (e) {
        $('body').css('overflow', 'auto');
        $('#background').hide();
    });
    })
});
}
$('button').click(function(){
    query(1);
    num();
})
var fengzi = $('#paging a b').first();
var fengmu = $('#paging a b').last();
var text;
//首页
    function first(){
        query(1);
        fengzi.text("1");
    }
//上一页    
    function previous(){
        var zi= parseInt(fengzi.text());
        var mu = parseInt(fengmu.text());
        if(zi>1){
        zi= zi-1;
        fengzi.text(zi);
        query(zi);
        }
    }
//下一页    
    function next(){
        var zi= parseInt(fengzi.text());
        var mu = parseInt(fengmu.text());
        if(zi<mu){
        zi= zi+1;
        fengzi.text(zi);
        query(zi);
        }
    }
//尾页    
    function last(){
        query(fengmu.text());
        fengzi.text(fengmu.text());
    }
    //跳转
  function jump(){
   var jump = $('[name=jump]').val();
   var mu = parseInt(fengmu.text());
   if(1<=jump&&jump<=mu){
        fengzi.text(jump);
        query(jump);
   }
  } 
function query(page){
    $('#result').empty();
    text="";
    var sr="";
    new Ajax("/product_result_query.jsp").keyvalue($('#form').serializeArray()).keyvalue("page",page).getJson(function(json){
        $.each(json,function(key,val){
            for(var i=0;i< val["honesty"];i++){
                sr+=" <img style='width:12px;height:12px;display: inline-block; margin-top:-25px;' src='../../img/huangguan.png'> ";
            }
             text += "<div lei='"+val["id"]+"'><img src='/upfile/"+val["pt"]+"'><p>"+val["name"]+"</p><h3><em>"+val["corpname"]+"</em><li style='width:76px; float:right; margin-top:-36px'>"+sr+"</li></h3></div>";
             sr="";
        })  
       $('#result').html(text);
        dianji(); 
     
    });
};
function num(){
    new Ajax("/product_result_page.jsp").keyvalue($('#form').serializeArray()).get(function(json){
         $('#num').text("共有"+json+"条");
         numb = Math.ceil(json.replace(/[^0-9]/ig, "")/12);
         fengmu.text(numb);
         fengzi.text("1");
    })
}

